cmake_minimum_required(VERSION 3.10.0)
project(easynote VERSION 0.1.0 LANGUAGES C CXX)

# 指定C标准
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED True)

# 设置输出目录
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")

# 设置VS源代码编码，还未测试是否有效
if(MSVC)
    add_compile_options("/source-charset:utf-8")
    add_compile_options("/execution-charset:utf-8")
endif()

# 源代码
set(EASYNOTE_SOURCE_FILES
    src/main.cpp
)

# 添加构建目标
if (CMAKE_BUILD_TYPE STREQUAL "Release")
    add_executable(easynote WIN32 ${EASYNOTE_SOURCE_FILES})
else()
    add_executable(easynote ${EASYNOTE_SOURCE_FILES})
endif()

# GCC/Clang 选项
target_compile_options(easynote PRIVATE
    # -Wno-unused-parameter   # 禁用未使用参数警告
    -Wall                   # 基本警告
    -Wextra                 # 额外警告
    -Wpedantic              # 严格模式
)

# glfw
add_subdirectory("./lib/glfw-3.4")

# OpenGL
find_package(OpenGL REQUIRED)

# dear imgui
set(DEAR_IMGUI_DIR ./lib/DearImGui-1.92.1/)
set(DEAR_IMGUI_SRC
    ${DEAR_IMGUI_DIR}/imgui_draw.cpp
    ${DEAR_IMGUI_DIR}/imgui_demo.cpp
    ${DEAR_IMGUI_DIR}/imgui_tables.cpp
    ${DEAR_IMGUI_DIR}/imgui_widgets.cpp
    ${DEAR_IMGUI_DIR}/imgui.cpp
    ${DEAR_IMGUI_DIR}/backends/imgui_impl_glfw.cpp
    ${DEAR_IMGUI_DIR}/backends/imgui_impl_opengl3.cpp
)
add_library(dear_imgui STATIC ${DEAR_IMGUI_SRC})
target_include_directories(dear_imgui PUBLIC
    ${DEAR_IMGUI_DIR}
    ${DEAR_IMGUI_DIR}/backends
)
target_link_libraries(dear_imgui glfw)

# 链接程序
target_link_libraries(easynote glfw OpenGL::GL dear_imgui)